package com.song.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.song.eduservice.entity.EduCourse;
import com.song.eduservice.entity.EduTeacher;
import com.song.eduservice.service.EduCourseService;
import com.song.eduservice.service.EduTeacherService;
import com.song.commonutils.ResultObj;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author song
 * @data 2020/4/3
 */

@RestController
@RequestMapping("/eduservice/indexfront")
@Api(description = "前台讲师课程管理")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * 查询前8条热门课程
     *
     * @return
     */

    @ApiOperation(value = "查询前8条热门课程")
    @GetMapping("/index")
    public Object index() {
        QueryWrapper<EduCourse> qw = new QueryWrapper<>();
        qw.eq("status","Normal");
        qw.last("limit 8");
        qw.orderByDesc("view_count");
        List<EduCourse> list = eduCourseService.list(qw);
        return list;
    }

    /**
     * 查询前4名师
     * @return
     */
    @ApiOperation(value = "查询前4名师")
    @GetMapping("/indexTeacher")
    public Object indexTeacher() {
        QueryWrapper<EduTeacher> qw = new QueryWrapper<>();
        qw.last("limit 4");
        qw.orderByDesc("id");
        List<EduTeacher> list = eduTeacherService.list(qw);
        return list;
    }
}
